home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 1 / Gold Medal Software Volume 1 (Gold Medal) (1994).iso / prog / dasv10_.arj / DAS.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-13  |  3.4 KB  |  159 lines

  1. // das.cpp file to test dice.lib, math.lib,
  2. // and util.lib function libraries
  3. #include <conio.h>
  4. #include <iostream.h>
  5. #include <stdlib.h>
  6. #include <time.h>
  7.  
  8. // math.lib
  9. long square(long);
  10. long cube(long);
  11. void count_up(long);
  12. void count_down(long);
  13. void compound_int(double,double,int);
  14. long fibonacci(long);
  15. long minimum(long,long,long);
  16. long maximum(long,long,long);
  17. long iterative_fact(long);
  18. long recursive_fact(long);
  19. // dice.lib
  20. int one_die(int,int,int,char[]);
  21. int two_dice(int,int,int,int,char[]);
  22. // util.lib
  23. void line_draw(void);
  24. void swap_p(int *,int *);
  25. void swap_r(int&,int&);
  26.  
  27. void main()
  28. {// begin demo
  29. TOP:
  30.  
  31. int num1,num2;
  32. long a,b,c,d,e,numb,res;
  33. double principal,rate;
  34. randomize();
  35.  
  36. // demonstrate minimum()
  37. cout<<"\nMinimum number";
  38. line_draw();
  39. cout<<"Enter three numbers: ";
  40. cin>>a>>b>>c;
  41. cout<<"Minimum is "<<minimum(a,b,c)<<"\n";
  42.  
  43. // demonstrate maximum()
  44. cout<<"Maximum number";
  45. line_draw();
  46. cout<<"Enter three numbers: ";
  47. cin>>a>>b>>c;
  48. cout<<"Maximum is "<<maximum(a,b,c)<<"\n";
  49.  
  50. // demonstrate count_up()
  51. cout<<"Count up numbers";
  52. line_draw();
  53. cout<<"Enter a number: ";
  54. cin>>c;
  55. count_up(c);
  56.  
  57. // demonstrate count_down()
  58. cout<<"Count down numbers";
  59. line_draw();
  60. cout<<"Enter a number: ";
  61. cin>>c;
  62. count_down(c);
  63.  
  64. // demonstrate cube()
  65. cout<<"Cube a number";
  66. line_draw();
  67. cout<<"Enter a number: ";
  68. cin>>c;
  69. cout<<"Cube of "<<c<<" is "<<cube(c)<<"\n";
  70.  
  71. // demonstrate square()
  72. cout<<"Square a number";
  73. line_draw();
  74. cout<<"Enter a number: ";
  75. cin>>c;
  76. cout<<"Square of "<<c<<" is "<<square(c)<<"\n";
  77.  
  78. // demonstrate compound_int()
  79. cout<<"Calculate Compound Interest";
  80. line_draw();
  81. cout<<"Enter the principal: ";
  82. cin>>principal;
  83. cout<<"Enter the rate: ";
  84. cin>>rate;
  85. cout<<"Enter the years: ";
  86. cin>>num1;
  87. cout<<" Year        Amount on deposit\n";
  88. compound_int(principal,rate,num1);
  89.  
  90. // demonstrate one_die()
  91. cout<<"Computer 1 Die Throw";
  92. line_draw();
  93. cout<<"Enter size of die: ";
  94. cin>>num1;
  95. cout<<"Enter delay for roll: ";
  96. cin>>num2;
  97.     for (d=1;d<=10;d++){
  98.     one_die(num1,num2,1,"One die: ");
  99.     cout<<"\n";
  100.     }
  101.  
  102. // demonstrate two_dice()
  103. cout<<"Computer 2 Dice Throw / Sum";
  104. line_draw();
  105. cout<<"Enter size of dice: ";
  106. cin>>num1;
  107. cout<<"Enter delay for roll: ";
  108. cin>>num2;
  109.     for (d=1;d<=10;d++){
  110.     two_dice(num1,num2,1,1,"Two dice: ");
  111.     cout<<"\n";
  112.     }
  113.  
  114. // demonstrate i_factorial() - iterative version
  115. cout<<"Iterative Factorial";
  116. line_draw();
  117. cout<<"Enter a number: ";
  118. cin>>e;
  119. cout<<e<<"! is "<<iterative_fact(e)<<"\n";
  120.  
  121. // demonstrate r_factorial() - recursive version
  122. cout<<"Recursive Factorial";
  123. line_draw();
  124. cout<<"Enter a number: ";
  125. cin>>e;
  126. cout<<e<<"! is "<<recursive_fact(e)<<"\n";
  127.  
  128. // demonstrate fibonacci()
  129. cout<<"Fibonacci numbers";
  130. line_draw();
  131. cout<<"Enter a number: ";
  132. cin>>numb;
  133. res = fibonacci(numb);
  134. cout<<"Fibonacci("<<numb<<") = "<<res<<"\n";
  135.  
  136. // demonstrate swap_p()
  137. cout<<"Swap with pointers";
  138. line_draw();
  139. cout<<"Enter two numbers: ";
  140. cin>>num1>>num2;
  141. cout<<"Numbers are "<<num1<<" and "<<num2<<"\n";
  142. swap_p(&num1,&num2);
  143. cout<<"Swapped numbers are "<<num1<<" and "<<num2<<"\n";
  144.  
  145. // demonstrate swap_r()
  146. cout<<"Swap with call by reference";
  147. line_draw();
  148. cout<<"Enter two numbers: ";
  149. cin>>num1>>num2;
  150. cout<<"Numbers are "<<num1<<" and "<<num2<<"\n";
  151. swap_r(num1,num2);
  152. cout<<"Swapped numbers are "<<num1<<" and "<<num2<<"\n";
  153.  
  154. cout<<"Run demo again (y/n) ? ";
  155. if (getche()=='y') goto TOP;
  156.  
  157. }// end demo
  158.  
  159.